from World import string, projectile
from random import Random
import constants

class StringGenerator(object):
    def __init__(self, engine, world):
        self.engine = engine
        self.world = world
        
    def generate(self):
        return string.String(x = self._next_x(), y = self._next_y(), length = self._next_length())
    
    def _next_x(self):
        return Random().randint(0, self.engine.get_screen().get_width())
    
    def _next_y(self):
        return Random().randint(constants.STRING_CEILING, constants.STRING_FLOOR)
    
    def _next_length(self):
        return Random().randint(constants.MIN_STRING_LENGTH, constants.MAX_STRING_LENGTH)
    
    def populate_world(self):
        if len(self.world.all_strings()) < constants.MAX_WORLD_STRINGS:
            self.world.add_object(self.generate())


class ProjectileGenerator(object):
    def __init__(self, engine, world):
        self.engine = engine
        self.world = world
        
    def generate(self):
        return projectile.Projectile(x = self._next_x(), y = self._next_y(), angle = self._next_angle(), speed = self._next_speed())
    
    def _next_x(self):
        return Random().randint(0, self.engine.get_screen().get_width())
    
    def _next_y(self):
        return 0

    def _next_angle(self):
        return Random().randint(190, 350)

    def _next_speed(self):
        return Random().randint(constants.MIN_PROJECTILE_SPEED, constants.MAX_PROJECTILE_SPEED)
    
    def populate_world(self):
        if len(self.world.all_projectiles()) < constants.MAX_PROJECTILES:
            self.world.add_object(self.generate())

